/*
 * Output.cpp
 *
 *  Created on: 2012. 11. 4.
 *      Author: dalxx
 */

#include <Arduino.h>
#include "Output.h"


namespace PLCLib {



OutputList::OutputList() {
	this->numOutput=0;
	this->outputList=NULL;
}

OutputList::~OutputList() {
	this->removeAll();
}



void OutputList::Out() {
	int i;
	for(i=0;i<this->numOutput;i++)
	{
		uint8_t val=((*this->outputList[i].status)?HIGH:LOW);
		digitalWrite(this->outputList[i].outPin,val);
	}
}



void OutputList::init(int num_output) {
	this->removeAll();
	this->numOutput=num_output;
	this->outputList=(Output*)malloc(this->numOutput*sizeof(Output));
}

void OutputList::removeAll() {
	free(this->outputList);
	this->outputList=NULL;
	this->numOutput=0;
}

void OutputList::setOutput(int index, uint8_t pin, bool* status) {
	this->outputList[index].outPin=pin;
	this->outputList[index].status=status;
	pinMode(pin, OUTPUT);
}



} /* namespace PLCLib */
